<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Puppet," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;使用puppet可以方便的进行文件管理，可以对文件的内容、属组、属主、权限等进行管理。可管理的文件类型包括普通文件、目录、链接文件。类型需要在ensure类型中明确指定。接下来从三个方面来介绍puppet文件管理的操作。 一、Puppet服务器端的配置 fileserver.conf文件的配置  &amp;#1">
<meta name="keywords" content="Puppet">
<meta property="og:type" content="article">
<meta property="og:title" content="Puppet学习之文件管理">
<meta property="og:url" content="https://hcldirgit.github.io/2017/09/03/Puppet/2. Puppet学习之文件管理/index.html">
<meta property="og:site_name" content="失落的乐章">
<meta property="og:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;使用puppet可以方便的进行文件管理，可以对文件的内容、属组、属主、权限等进行管理。可管理的文件类型包括普通文件、目录、链接文件。类型需要在ensure类型中明确指定。接下来从三个方面来介绍puppet文件管理的操作。 一、Puppet服务器端的配置 fileserver.conf文件的配置  &amp;#1">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2017-09-02T17:30:19.235Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Puppet学习之文件管理">
<meta name="twitter:description" content="&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;使用puppet可以方便的进行文件管理，可以对文件的内容、属组、属主、权限等进行管理。可管理的文件类型包括普通文件、目录、链接文件。类型需要在ensure类型中明确指定。接下来从三个方面来介绍puppet文件管理的操作。 一、Puppet服务器端的配置 fileserver.conf文件的配置  &amp;#1">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://hcldirgit.github.io/2017/09/03/Puppet/2. Puppet学习之文件管理/"/>





  <title>Puppet学习之文件管理 | 失落的乐章</title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  




<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', '85*****1', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?87980c**************99ec5e26fb5";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>











  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">失落的乐章</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">技术面前，永远都是学生。</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-message">
          <a href="/message" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-external-link"></i> <br />
            
            留言
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://hcldirgit.github.io/2017/09/03/Puppet/2. Puppet学习之文件管理/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="失落的乐章">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/0.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="失落的乐章">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Puppet学习之文件管理</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-03T02:09:22+08:00">
                2017-09-03
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;使用puppet可以方便的进行文件管理，可以对文件的内容、属组、属主、权限等进行管理。可管理的文件类型包括普通文件、目录、链接文件。类型需要在ensure类型中明确指定。接下来从三个方面来介绍puppet文件管理的操作。</p>
<h2 id="一、Puppet服务器端的配置"><a href="#一、Puppet服务器端的配置" class="headerlink" title="一、Puppet服务器端的配置"></a>一、Puppet服务器端的配置</h2><ol>
<li>fileserver.conf文件的配置</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;vim fileserver.conf 添加如下内容，在puppet master上创建一个文件存放目录</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line">[files]</div><div class="line">path /etc/puppet/files</div><div class="line">allow 10.1.4.0/24</div></pre></td></tr></table></figure>
<ol>
<li>site.pp文件的配置</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;最好是更改其他的文件，然后用这个文件import进来，我这里为了测试简便就直接更改这个文件了，具体的如何操作见后面的实战部分。</p>
<h2 id="二、Puppet文件管理重要参数介绍"><a href="#二、Puppet文件管理重要参数介绍" class="headerlink" title="二、Puppet文件管理重要参数介绍"></a>二、Puppet文件管理重要参数介绍</h2><ol>
<li>backup参数</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;指定在文件内容替换之前进行备份操作，可以备份在本地，也可以集中备份。集中远程备份的话可以使用filebucket（我们在后面的实战部分会进行详细介绍），这个备份的时候如果备份在本地可以指定备份的文件名。</p>
<ol>
<li>content参数</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;指定文件的内容(字符串)，这个参数和source、target参数冲突。</p>
<ol>
<li>ensure参数</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这个参数指定是否创建、删除文件或者目录，有present、absent、file、directory等值。其中present会检查文件是否存在，不存在就会创建一个空文件。absent会删除文件或者目录，如果是目录需要指定recurse参数指定是否允许递归。如果指定的是其他的参数，则会创建连接文件，为了方便管理，建议在创建的时候使用ensure =&gt; link,并通过target参数指定文件。注意不能在windows系统上链接文件，</p>
<ol>
<li>force参数</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;该参数强制执行文件操作，进行如下操作的时候必须指定force参数</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;purge 子目录</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;用文件或者链接文件替换目录</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;使用ensure =&gt; absent参数删除目录</p>
<ol>
<li>group参数</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;指定文件或者目录的属组，可以是组名或者组id，如果是windows的话属组和属主不能相同。</p>
<ol>
<li>ignore参数</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这个参数指定在递归期间对符合指定的模式的文件操作将被忽略。</p>
<ol>
<li>links参数</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这个参数指定处理文件期间如何处理链接文件，可以设置follow和manage。在拷贝文件的时候，follow将会拷贝目标文件代替链接文件，manage将只会拷贝链接文件，ignore将会跳过。</p>
<ol>
<li>mode参数</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这个参数用来指定文件或者目录的权限，puppet使用传统的unix权限方案，如果系统采用的权限方案不同的，puppet为这些系统将权限翻译成等价的权限，比如windows。这些权限可以是数字(r=4,w=2,x=1)也可以是字符(rwxst)。</p>
<ol>
<li>owner参数</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;指定文件的属主，可以是用户名或是用户id，如果是windows的话属组和属主不能相同。</p>
<ol>
<li>path参数</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;指定文件管理的路径。Windows路径也使用/而不是\。</p>
<ol>
<li>purge参数</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这个参数会删除在master上不存在的文件，这个参数只有在管理目录的时候指定了recurse =&gt; true参数的时候才有意义。</p>
<ol>
<li>recurse参数</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这个参数指定是否进行递归调用以及递归调用的深度，选项如下</p>
<ul>
<li>inf,true  —在远程和本地都进行递归调用</li>
<li>remote —只在远程进行递归调用</li>
<li>false —不进行递归调用</li>
<li>[0-9]+ —和true参数一样，但是限制递归调用目录的深度</li>
</ul>
<ol>
<li>source参数</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;该参数指定将会被拷贝到指定位置的资源文件，值可以是指定远程文件的URIS或者本地的完整路径。可以指定多个sorce，这个参数和content、target冲突。</p>
<ol>
<li>target参数</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;这个参数指定创建链接文件的目标文件或者目录。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;上面只是列了一些常用的选项，更多选项请参考：</p>
<p><a href="https://docs.puppet.com/puppet/latest/type.html#augeas-attributes" target="_blank" rel="external">https://docs.puppet.com/puppet/latest/type.html#augeas-attributes</a></p>
<h3 id="三、Puppet文件管理实战"><a href="#三、Puppet文件管理实战" class="headerlink" title="三、Puppet文件管理实战"></a>三、Puppet文件管理实战</h3><ol>
<li>使用filebucket进行远程备份。</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Filebucket的配置</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">vim site.pp</div></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"><span class="comment">#添加filebucket的配置</span></div><div class="line">filebucket &#123; <span class="string">'main'</span>:</div><div class="line">    server =&gt; <span class="string">"puppet.zhang.com"</span>,</div><div class="line">    path =&gt; <span class="literal">false</span>,</div><div class="line">&#125;</div><div class="line"><span class="comment">#让节点node1.zhang.com进行远程备份</span></div><div class="line">node <span class="string">'node1.zhang.com'</span>&#123;</div><div class="line">file &#123; <span class="string">"/etc/test2"</span>:</div><div class="line">    <span class="built_in">source</span> =&gt; <span class="string">"puppet://puppet.zhang.com/files/test2"</span>,</div><div class="line">    backup =&gt; main</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;如果没有设置bucketdir路径，那么默认文件保存在master的$vardir/bucket路径。存储是以文件的md5值为目录，目录下面存储了文件的路径和内容，因此获取备份文件的内容和恢复都需要使用到文件的md5值。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在agent通过filebucket客户端获取文件的内容</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">puppet filebucket get 4894b816078bcca4b63a6feaaf38aff8</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在agent通过filebucket客户端还原文件的内容</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">puppet filebucket restore /etc/test2 4894b816078bcca4b63a6feaaf38aff8</div></pre></td></tr></table></figure>
<ol>
<li>将master上文件目录下的一个文件，复制到agent的指定位置，如果文件存在就先对文件进行备份然后覆盖。</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;配置代码如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">node <span class="string">'node1.zhang.com'</span>&#123;</div><div class="line">         file &#123;<span class="string">"/etc/test1"</span>:</div><div class="line">         <span class="built_in">source</span> =&gt; <span class="string">"puppet://puppet.zhang.com/files/test1"</span>,</div><div class="line">         backup =&gt; <span class="string">".bak_<span class="variable">$uptime_seconds</span>"</span>,</div><div class="line">&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<ol>
<li>将 agent 上的一个文件复制成另外一个文件，如果目的文件存在就先做备份再覆盖，并制定文件属master和权限。</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;配置代码如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">node <span class="string">'node1.zhang.com'</span>&#123;</div><div class="line">        file &#123;<span class="string">"/tmp/test2"</span>:</div><div class="line">        <span class="built_in">source</span> =&gt; <span class="string">"/etc/passwd"</span>,</div><div class="line">        backup =&gt; <span class="string">".bak_<span class="variable">$uptime_seconds</span>"</span>,</div><div class="line">        group =&gt; nobody,</div><div class="line">        owner =&gt; nobody,</div><div class="line">        mode =&gt; 600;</div><div class="line">&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<ol>
<li>在agent上创建/tmp/test3，并制定文件的内容为test3。</li>
</ol>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;配置代码如下：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">node <span class="string">'node1.zhang.com'</span>&#123;</div><div class="line">        file &#123;<span class="string">"/tmp/test3"</span>:</div><div class="line">        content =&gt; <span class="string">"test3"</span>&#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<ol>
<li>对agent上的某个文件或者文件夹建立软连接。</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">node <span class="string">'node1.zhang.com'</span>&#123;</div><div class="line">file &#123;<span class="string">"/tmp/test4"</span>:</div><div class="line">        ensure =&gt; link,</div><div class="line">        target =&gt; <span class="string">"/var/log/messages"</span>;</div><div class="line">        <span class="string">"/tmp/test5"</span>:</div><div class="line">        ensure =&gt; link,</div><div class="line">        target =&gt; <span class="string">"/var/log"</span>;</div><div class="line">        &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;也可以简写成如下代码：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">node <span class="string">'node1.zhang.com'</span>&#123;</div><div class="line">file &#123;<span class="string">"/tmp/test4"</span>:</div><div class="line">        ensure =&gt; <span class="string">"/var/log/messages"</span>;</div><div class="line">        <span class="string">"/tmp/test5"</span>:</div><div class="line">        ensure =&gt; <span class="string">"/var/log"</span>;</div><div class="line">        &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<ol>
<li>如果agent上/tmp/test6文件存在的话就删除掉agent上的/tmp/test6文件。</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">node <span class="string">'node1.zhang.com'</span>&#123;</div><div class="line">file &#123;<span class="string">"/tmp/test6"</span>:</div><div class="line">        ensure =&gt; absent;</div><div class="line">        &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<ol>
<li>如果agent上不存在/tmp/test7文件就在agent上创建/tmp/test6文件。</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">node <span class="string">'node1.zhang.com'</span>&#123;</div><div class="line">file &#123;<span class="string">"/tmp/test7"</span>:</div><div class="line">        ensure =&gt; present;</div><div class="line">        &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<ol>
<li>在agent上创建目录。</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">node <span class="string">'node1.zhang.com'</span>&#123;</div><div class="line">file &#123;</div><div class="line">      <span class="string">"/tmp/test8"</span>:</div><div class="line">      ensure =&gt; directory;</div><div class="line">      &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<ol>
<li>删除agent上面的目录。</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">node <span class="string">'node1.zhang.com'</span>&#123;</div><div class="line">file &#123; <span class="string">"/tmp/test9/"</span>:</div><div class="line">       ensure =&gt; absent,</div><div class="line">       force =&gt; <span class="literal">true</span>;</div><div class="line">       &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<ol>
<li>类似rsync，将master上面的文件目录同步到agent上，不同步含有log的文件和目录，如果含有子目录，递归到子目录，删除master上没有agent上有的文件或者目录。</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">node <span class="string">'node1.zhang.com'</span>&#123;</div><div class="line">file &#123;<span class="string">"/tmp/test10"</span>:</div><div class="line">        ensure =&gt; directory,</div><div class="line">        <span class="built_in">source</span> =&gt; <span class="string">"puppet://puppet.zhang.com/files/"</span>,</div><div class="line">        ignore =&gt; <span class="string">'*log*'</span>,</div><div class="line">        recurse =&gt; <span class="literal">true</span>,</div><div class="line">        purge =&gt; <span class="literal">true</span>,</div><div class="line">        force =&gt; <span class="literal">true</span>,</div><div class="line">     &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="四、参考文档"><a href="#四、参考文档" class="headerlink" title="四、参考文档"></a>四、参考文档</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<a href="http://docs.puppetlabs.com/references/stable/configuration.html" target="_blank" rel="external">http://docs.puppetlabs.com/references/stable/configuration.html</a></p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Puppet/" rel="tag"># Puppet</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/09/03/Puppet/1. Puppet安装和配置/" rel="next" title="Puppet安装和配置">
                <i class="fa fa-chevron-left"></i> Puppet安装和配置
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/09/03/Puppet/3. Puppet cron/" rel="prev" title="Puppet cron">
                Puppet cron <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/0.png"
               alt="失落的乐章" />
          <p class="site-author-name" itemprop="name">失落的乐章</p>
           
              <p class="site-description motion-element" itemprop="description">失落的乐章的Blog</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/">
                <span class="site-state-item-count">627</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">38</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/hcldirgit" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#一、Puppet服务器端的配置"><span class="nav-number">1.</span> <span class="nav-text">一、Puppet服务器端的配置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#二、Puppet文件管理重要参数介绍"><span class="nav-number">2.</span> <span class="nav-text">二、Puppet文件管理重要参数介绍</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#三、Puppet文件管理实战"><span class="nav-number">2.1.</span> <span class="nav-text">三、Puppet文件管理实战</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#四、参考文档"><span class="nav-number">3.</span> <span class="nav-text">四、参考文档</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">失落的乐章</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  






  





  

  

  

  

  

  

</body>
</html>
